﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using intera = System.Windows.Interactivity;

namespace MoneyBook.Interactivity {
    public class ActionCompletedTrigger : intera.TriggerBase<DependencyObject> {
        
        protected override void OnAttached() {
            base.OnAttached();
            if(!(this.AssociatedObject is INotifyActionCompleted)){
                return;
            }
            INotifyActionCompleted target = this.AssociatedObject as INotifyActionCompleted;
            target.ActionCompleted -= AssociatedObject_ActionCompleted;
            target.ActionCompleted += AssociatedObject_ActionCompleted;
        }

        protected override void OnDetaching() {
            base.OnDetaching();
            if (!(this.AssociatedObject is INotifyActionCompleted)) {
                return;
            }
            INotifyActionCompleted target = this.AssociatedObject as INotifyActionCompleted;
            target.ActionCompleted -= AssociatedObject_ActionCompleted;
        }

        private void AssociatedObject_ActionCompleted(object sender, ActionCompletedEventArgs e) {
            this.InvokeActions(e);
        }
    }
}
